
#include <iostream>
#include "Stock.hh"

static Stock stocks[10] = {
    {1, 0.1},
    {2, 0.2},
    {3, 0.3},
    {4, 0.4},
    {5, 0.5},
    {6, 0.6},
    {7, 0.7},
    {8, 0.8},
    {9, 0.9},
    {10, 0.10},
};

static int for_code_get_index(int code)
{
    for (int i = 0; i < 10; ++i)
    {
        if (stocks[i].code == code)
        {
            return i;
        }
    }

    return -1;
}

void StockList(void)
{
    for (int i = 0; i < 10; ++i)
    {
        std::cout << "Stock Code:" << stocks[i].code << "\tStock value:" << stocks[i].value << std::endl;
    }
}

void StockUpdate(int code, float value)
{
    int index = for_code_get_index(code);
    if (index != -1)
    {
        stocks[index].code = code;
        stocks[index].value = value;
        std::cout << "Stock Code " << code << " Update Suceess!\n";
    }
    else
    {
        std::cout << "Stock Code " << code << " Not found!\n";
    }
}